//
//  VRHomeTableHeaderView.m
//  VRFirefighting
//
//  Created by Veer on 2018/8/12.
//  Copyright © 2018年 Veer. All rights reserved.
//

#import "VRHomeTableHeaderView.h"


@interface VRHomeTableHeaderView()

@property (nonatomic, strong) UIView *containView;
@property (nonatomic, weak) UILabel *detailLbl;
@property (nonatomic, weak) UIImageView *accessoryImgView;
@property (nonatomic, assign) UIView *bottomLineView;

@end

@implementation VRHomeTableHeaderView

+ (instancetype)headerWith:(UITableView *)tableview
{
    static NSString *headerID = @"VRHomeTableHeaderView";
    VRHomeTableHeaderView *headerView = [tableview dequeueReusableHeaderFooterViewWithIdentifier:headerID];
    if (headerView == nil) {
        
        headerView = [[VRHomeTableHeaderView alloc] initWithReuseIdentifier:headerID];
    }
    return headerView;
}


- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        
        [self setupSubView];
    }
    return self;
}

- (void)setupSubView
{
    
    UIView *containView = [[UIView alloc] init];
    containView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:containView];
    self.containView = containView;
    
    UIImageView *iconImgView = [[UIImageView alloc] init];
    iconImgView.contentMode = UIViewContentModeScaleAspectFit;
    [self.containView addSubview:iconImgView];
    self.iconImgView = iconImgView;
    
    UILabel *titleLbl = [[UILabel alloc] init];
    titleLbl.textColor = MAINColor;
    titleLbl.font = VRFont(16);
//    titleLbl.textAlignment = NSTextAlignmentRight;
    [self.containView addSubview:titleLbl];
    self.titleLbl = titleLbl;

    UILabel *detailLbl = [[UILabel alloc] init];
    detailLbl.text = @"更多";
    detailLbl.textColor = MAINColor;
    detailLbl.font = VRFont(14);
    detailLbl.textAlignment = NSTextAlignmentRight;
    [self.containView addSubview:detailLbl];
    self.detailLbl = detailLbl;
    
    UIImageView *accessoryImgView = [[UIImageView alloc] init];
    accessoryImgView.image = [UIImage imageNamed:@"i_right"];
    accessoryImgView.contentMode = UIViewContentModeScaleAspectFit;
    [self.containView addSubview:accessoryImgView];
    self.accessoryImgView = accessoryImgView;
    
    UIView *bottomLineView = [[UIView alloc] init];
    bottomLineView.backgroundColor = RGB(228, 228, 228);
    [self.containView addSubview:bottomLineView];
    self.bottomLineView = bottomLineView;
    
    UITapGestureRecognizer *tapGeture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesture:)];
    [containView addGestureRecognizer:tapGeture];
}


#pragma mark - action
- (void)tapGesture:(UITapGestureRecognizer *)tapGesture
{
    if (self.moreClickBlock) {
        self.moreClickBlock();
    }
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    
    [self.containView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(10);
        make.bottom.mas_equalTo(0);
    }];
    
    [self.iconImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.centerY.mas_equalTo(self.containView);
        make.width.mas_equalTo(20);
        make.height.mas_equalTo(20);
    }];
    
    [self.titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.iconImgView.mas_right).offset(6);
        make.centerY.mas_equalTo(self.containView);
    }];
    
    [self.accessoryImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-20);
        make.centerY.mas_equalTo(self.containView);
        make.width.mas_equalTo(12);
        make.height.mas_equalTo(12);
    }];
    
    [self.detailLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.accessoryImgView.mas_left).offset(-4);
        make.centerY.mas_equalTo(self.containView);
    }];
    
    [self.bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(self.containView);
        make.bottom.mas_equalTo(self.containView);
        make.height.mas_equalTo(0.5);
    }];
}




@end
